import {Component, OnInit, ViewChild} from '@angular/core';
import {_HttpClient, DrawerHelper, ModalHelper} from '@delon/theme';
import {NzMessageService} from 'ng-zorro-antd';
import {IsystemPermissionAddComponent} from './permission-add/permission-add.component';
import {STColumn} from "@delon/abc";
import {TreeTableComponent} from "@shared";


@Component({
  selector: 'app-isystem-permission',
  templateUrl: './permission.component.html',
  styles: [
      `
    `
  ]
})
export class IsystemPermissionComponent implements OnInit {
  @ViewChild('st', { static: false })
  st: TreeTableComponent;
  url = `sys/permission/list`;
  columns: STColumn[] = [
    {title: '标题', index: 'name'},
    {title: '菜单类型', index: 'menuType_dictText'},
    {title: 'icon', index: 'icon'},
    {title: 'url', index: 'url'},
    {title: '序号', index: 'sortNo'},
    {
      title: '操作',
      buttons: [
        {
          text: '编辑',
          type: 'drawer',
          drawer: {
            title: '编辑',
            paramsName:'record',
            component: IsystemPermissionAddComponent,
          },
        },
        {
          text: '更多',
          children: [
            {
              text: `删除`,
              type: 'del',
              click: (record) => this.http.delete(`sys/user/delete?id=${record.id}`).subscribe(res =>this.st.reload())
            },
            {
              text: `数据权限`,
              type: 'none',
              pop:true,
              popTitle:'确认冻结吗？',
              click: (record, modal, comp) => {
                this.http.post(`sys/user/frozenBatch`,{'ids':record.id,'status':2}).subscribe(res => {
                  this.st.reload()
                })
              }
            },
          ]
        },
      ]
    }
  ];


  constructor(
    private http: _HttpClient,
    private modal: ModalHelper,
    private drawerHelper: DrawerHelper,
    private message: NzMessageService
  ) {
  }

  ngOnInit() {

  }

  add() {
    this.drawerHelper
      .create("添加",IsystemPermissionAddComponent, {i:{menuType:0,add:true}})
      .subscribe();
  }

  save(value) {
    this.http.put(`sys/permission/edit`, value).subscribe()
  }

  delete(value) {
    this.http.delete(`sys/permission/delete?id=${value.key}`).subscribe()
  }

}
